package com.yulongtian.oneProblemEveryDay.month202301;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
 * https://leetcode.cn/problems/finding-the-users-active-minutes/
 * 可
 *
 * @author yulongTian
 * @create 2023-01-20 21:56
 */
public class Test15 {
    public static void main(String[] args) {
        int[][] logs = {{0, 5}, {1, 2}, {0, 2}, {0, 5}, {1, 3}};
        int k = 5;
        System.out.println(Arrays.toString(findingUsersActiveMinutes(logs, k)));
    }

    public static int[] findingUsersActiveMinutes(int[][] logs, int k) {
        int[] answer = new int[k];
        HashMap<Integer, HashSet<Integer>> map = new HashMap<>();
        for (int[] log : logs) {
            int id = log[0];
            int time = log[1];
            if (!map.containsKey(id)) {
                HashSet<Integer> temp = new HashSet<>();
                temp.add(time);
                map.put(id, temp);
            } else {
                map.get(id).add(time);
            }
        }
        for (Integer key : map.keySet()) {
            answer[map.get(key).size() - 1]++;
        }

        return answer;
    }
}
